function varargout = GRAFICA(varargin)
% GRAFICA MATLAB code for GRAFICA.fig
%      GRAFICA, by itself, creates a new GRAFICA or raises the existing
%      singleton*.
%
%      H = GRAFICA returns the handle to a new GRAFICA or the handle to
%      the existing singleton*.
%
%      GRAFICA('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GRAFICA.M with the given input arguments.
%
%      GRAFICA('Property','Value',...) creates a new GRAFICA or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before GRAFICA_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to GRAFICA_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help GRAFICA

% Last Modified by GUIDE v2.5 19-Nov-2014 00:52:39

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @GRAFICA_OpeningFcn, ...
                   'gui_OutputFcn',  @GRAFICA_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before GRAFICA is made visible.
function GRAFICA_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to GRAFICA (see VARARGIN)

% Choose default command line output for GRAFICA
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes GRAFICA wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = GRAFICA_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in GRAFICA.
function GRAFICA_Callback(hObject, eventdata, handles)
% hObject    handle to GRAFICA (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global Estado;
  



    Estado=serial('COM13');
    set(Estado,'BaudRate',9600);
    set(Estado,'DataBits',8);
    set(Estado,'Parity','none');
     set(Estado,'Terminator','LF');
    set(Estado,'StopBits',1);
    set(Estado,'FlowControl','none');
    fopen(Estado);

    
Estado.BytesAvailable; 
title('GRAFICA VOLTAJE ADC-SERIAL');
xlabel('Numero de Muestras');
ylabel('Voltaje (V)');
grid off;
hold on;
%pause(1);
A = fscanf(Estado,'%c',1);
 %pause(1);

% if eq(A,'A')
% 
%  interv=200;
% passo=100;
% t=1;
% 
% while(t<interv)
% 
% y=[200,10];
% x=[300,50];
% plot(x,y);
% axis([0,interv,0,200]);
% grid
% t=t+passo;
% drawnow;
% end

   
     interv=200;
    passo=100;
    t=1;

    while(t<interv)

    
   ylim([0 100]);
    xlim([0 200]);
         if eq(A,'A')
        
         y=[200,10];
         x=[300,50];
        
         else
              if eq(A,'B')
        
            y=[100,5];
            x=[10,25];
             
              end
         end
         plot(x,y);
         
   
   % axis([0,interv,0,200]);
    grid
    t=t+passo;
    drawnow;

    end

    
   
    
    
    
    
   
    
    
% --- Executes on button press in CONECTA.
function CONECTA_Callback(hObject, eventdata, handles)
% hObject    handle to CONECTA (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

 global Estado;
    Estado=serial('COM13');
    set(Estado,'BaudRate',9600);
    set(Estado,'DataBits',8);
    set(Estado,'Parity','none');
     set(Estado,'Terminator','LF');
    set(Estado,'StopBits',1);
    set(Estado,'FlowControl','none');
    fopen(Estado);
% --- Executes on button press in DESCONECTA.
function DESCONECTA_Callback(hObject, eventdata, handles)
% hObject    handle to DESCONECTA (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global Estado;
    fclose(Estado);
    delete(Estado)
    clear Estado
    delete(instrfind({'Port'},{'COM13'}))
